package test.service;

import org.zw.android.framework.async.AsyncTaskExecutor;
import org.zw.android.framework.async.AsyncTaskRunnable;
import org.zw.android.framework.async.Worker;

public class WebServiceImpl {

	private static WebServiceImpl _instance ;
	
	private WebServiceImpl(){
		
	}
	
	public static void initWebService(){
		
		if(_instance == null){
			_instance	= new WebServiceImpl() ;
		}
	}
	
	public static WebServiceImpl getWebService(){
		return _instance ;
	}
	
	public void test(){
		
		AsyncTaskExecutor.executeSingleTask(new AsyncTaskRunnable() {

			@Override
			public Object onProcessing() {
				
				long enter = System.currentTimeMillis() ;
				
				while(true){
					
					if(System.currentTimeMillis() - enter > 20 * 1000){
						break ;
					}
					
					try{
						Thread.sleep(100);
						
						System.out.println("Thread ---------Sleep");
					} catch(Exception e){
						
					}
				}
				
				return null;
			}

			@Override
			public void onFinish(Object value) {
				
			}
		}) ;
	}
	
	public Worker login(String username,String password,AppHanlder handler){
		
		Worker worker = AsyncTaskExecutor.execute(new AsyncTaskRunnable(handler) {
			
			@Override
			public Object onProcessing() {
				
				Object obj = null ;
				
				long enter = System.currentTimeMillis() ;
				
				while(true){
					
					if(System.currentTimeMillis() - enter > 10 * 1000){
						break ;
					}
					
					try{
						
						Thread.sleep(100);
						
						System.out.println("zhouwei task------------------->" + ((System.currentTimeMillis() - enter) / 1000));
					} catch(Exception e){
						
					}
				}
				
				System.out.println(obj.toString());
				
				return "zhouwei";
			}

			@Override
			public void onFinish(Object value) {
				
			}
		}) ;
		
		return worker ;
	}
}
